package cn.yunhe.service.impl;

import cn.yunhe.dao.DeptDao;
import cn.yunhe.model.Dept;
import cn.yunhe.model.Page;
import cn.yunhe.service.IDeptService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
@Component
@Service("deptService")
public class DeptServiceImpl implements IDeptService {

    @Resource
    private DeptDao deptDao;
    @Override
    public Page queryLikeDept(Map<String, Object> cond) {
        Page page = new Page();
        //总记录数
        int totalNum = deptDao.getLikeCountDept(cond);
        page.setTotalNum(deptDao.getLikeCountDept(cond));
        //每页记录数
        int pageSize = Integer.parseInt(String.valueOf(cond.get("pageSize")));
        page.setPageSize(pageSize);
        //当前页码
        int pageNum = Integer.parseInt(String.valueOf(cond.get("pageNum")));
        page.setPageNum(Integer.parseInt(String.valueOf(cond.get("pageNum"))));
        //总页数
        int totalPage = totalNum/pageSize + (totalNum%pageSize == 0 ? 0 : 1);
        page.setTotalPage(totalPage);
        page.setResult(deptDao.getLikeDept(cond));
        return page;
    }

    @Override
    public void addDept(Dept dept) {
        deptDao.addDept(dept);
    }

    @Override
    public void delDept(Dept dept) {
        deptDao.delDept(dept);
    }

    @Override
    public Dept findDept(Dept dept) {
        return deptDao.findDept(dept);
    }

    @Override
    public void editDept(Dept dept) {
        deptDao.editDept(dept);
    }

    public DeptDao getDeptDao() {
        return deptDao;
    }

    public void setDeptDao(DeptDao deptDao) {
        this.deptDao = deptDao;
    }
}
